define(['app'],function(app){return {module: function($scope, $http, eventBusService, httpService, params) {
	
	$scope.form.fk_user = params.id;
	//查询教职工单位数据
	$scope.find = function(){
		httpService.postpage(app.urls.user_unit_select,$scope.form,function(data){
			if("0000" === data.code){
    			$scope.rows = data.data;
    		}else{
    			alert(data.msg);
    		}
		});
	}
	
	$scope.find();
	
	$scope.add = function(){
		eventBusService.publish("modal.page","modules/content/usermanagement/teacherCenter/setunit/add?id="+params.id);
	}
	
	$scope.update = function(){
		var values = [];
		$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
			values.push($(this).val());
		});
		if(values.length < 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择修改数据。"});
		}else if(values.length > 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"您选择了多行数据，请重新选择。"});
		}else {
			var id = values[0].split(',')[0];
			var fk_user =  values[0].split(',')[1];
			console.log(values[0])
			console.log(id)
		    console.log(fk_user)
			eventBusService.publish("modal.page","modules/content/usermanagement/teacherCenter/setunit/update?id="+id+"&fk_user="+fk_user);
		}
	}
	
	$scope.delete = function(){
		var values = [];
		var ids="";
		$('#'+$scope.controllerName+' input[name="dataPk"]:checked').each(function(){
			var arr=$(this).val().split(',');
			values.push(arr[0]);
			ids = ids+",'"+arr[0]+"'";
		});

		if(values.length < 1){
			eventBusService.publish('modal.alert', {"title":"操作提示","content":"请选择您要删除数据。"});
		}else{
			eventBusService.publish("modal.alert",{"content":"你是否确认删除这"+values.length+"条数据？","isAutoClose":false,"confirm":function(){
				httpService.post(app.urls.user_unit_delete,{"id":ids.replace(',','')},function(data){
					if("0000" === data.code){
						$scope.page.current = 1;
				    	//执行查询班级数据
				    	$scope.find();
					}else{
						alert(data.msg);
					}
				});
			},"cancel":function(){
				//用户取消，不做操作
			}});
		}
	}
	
	//接收数据刷新
	eventBusService.subscribe('content.page.reload', function(event,data) {
		$scope.page.current = 1;
    	//执行查询班级数据
    	$scope.find();
	});
}}});